package com.ninghushangbao.ninghu.utils;

import sun.misc.BASE64Encoder;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5utils {
    //MD5加密方法
    public String EncoderByMd5(String str){
        String md5Str=null;
        try{
            //获取加密算法
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            //加密后的字符串
            BASE64Encoder base64en = new BASE64Encoder();
            md5Str = base64en.encode(md5.digest(str.getBytes("utf-8")));
        }
        catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return md5Str;
    }

}
